package com.twotwoshop.domin.chat.vos;

import lombok.Data;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * 消息列表vo
 */
@Data
public class ChatMessageVo implements Comparable<ChatMessageVo> {


    //id: 会话唯一标识
    private Long id;

    // senderId: 发送消息用户的ID
    private Long senderId;      // 发送者ID

    private String senderName; // senderName: 发送消息用户的昵称

    private String senderAvatar; //senderAvatar: 发送消息用户的头像

    private Long goodsId;       // 商品ID

    private String goodsTitle;  //商品标题

    private Long receiverId;    // 接收者ID

    private String goodsImage;   //: 商品图片;

    private String lastMessage;      //: 最后一条消息的内容

    private Date lastTime; //: 最后一条消息的发送时间(时间戳);    // 发送时间

    private Integer unreadCount; //: 未读消息数量;       // 消息类型(0:文本 1:图片)


    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     *
     * <p>The implementor must ensure
     * {@code sgn(x.compareTo(y)) == -sgn(y.compareTo(x))}
     * for all {@code x} and {@code y}.  (This
     * implies that {@code x.compareTo(y)} must throw an exception iff
     * {@code y.compareTo(x)} throws an exception.)
     *
     * <p>The implementor must also ensure that the relation is transitive:
     * {@code (x.compareTo(y) > 0 && y.compareTo(z) > 0)} implies
     * {@code x.compareTo(z) > 0}.
     *
     * <p>Finally, the implementor must ensure that {@code x.compareTo(y)==0}
     * implies that {@code sgn(x.compareTo(z)) == sgn(y.compareTo(z))}, for
     * all {@code z}.
     *
     * <p>It is strongly recommended, but <i>not</i> strictly required that
     * {@code (x.compareTo(y)==0) == (x.equals(y))}.  Generally speaking, any
     * class that implements the {@code Comparable} interface and violates
     * this condition should clearly indicate this fact.  The recommended
     * language is "Note: this class has a natural ordering that is
     * inconsistent with equals."
     *
     * <p>In the foregoing description, the notation
     * {@code sgn(}<i>expression</i>{@code )} designates the mathematical
     * <i>signum</i> function, which is defined to return one of {@code -1},
     * {@code 0}, or {@code 1} according to whether the value of
     * <i>expression</i> is negative, zero, or positive, respectively.
     *
     * @param o the object to be compared.
     * @return a negative integer, zero, or a positive integer as this object
     * is less than, equal to, or greater than the specified object.
     * @throws NullPointerException if the specified object is null
     * @throws ClassCastException   if the specified object's type prevents it
     *                              from being compared to this object.
     */
    @Override
    public int compareTo(ChatMessageVo o) {

        //根据时间戳转化为毫秒值排序  升序
        return (int) (this.getLastTime().getTime() - o.getLastTime().getTime());

    }
}
